﻿using MediatR;
using T.Settlement.API.Application.Command.PaymentCommand;
using T.Settlement.Repository.SettlementInterface;

namespace T.Settlement.API.Application.CommandHandlers.PaymentHandler
{
    public class PaymentUpdStatusCommandHandler : IRequestHandler<PaymentUpdStatusCommand, int>
    {
        private readonly IPaymentSRepository _paymentSRepository;
        public PaymentUpdStatusCommandHandler(IPaymentSRepository paymentSRepository)
        {
            _paymentSRepository = paymentSRepository;
        }
        public async Task<int> Handle(PaymentUpdStatusCommand request, CancellationToken cancellationToken)
        {
            var paymentStatus = (await _paymentSRepository.GetAllAsync()).Where(x => x.PaymentId == request.PaymentId).FirstOrDefault();
            paymentStatus.ApprovalStatus = request.ApprovalStatus;
            return await _paymentSRepository.Update(paymentStatus);
        }
    }
}
